]>
Commit | Line | Data |
---|---|---|
be897af3 RBR |
1 | // Copyright (C) 2024 Rubén Beltrán del Río |
2 | ||
3 | // This program is free software: you can redistribute it and/or modify | |
4 | // it under the terms of the GNU General Public License as published by | |
5 | // the Free Software Foundation, either version 3 of the License, or | |
6 | // (at your option) any later version. | |
7 | ||
8 | // This program is distributed in the hope that it will be useful, | |
9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | // GNU General Public License for more details. | |
12 | ||
13 | // You should have received a copy of the GNU General Public License | |
14 | // along with this program. If not, see https://map.tranquil.systems. | |
5e8ff485 RBR |
15 | import SwiftUI |
16 | ||
17 | struct MapAxes: View { | |
18 | ||
5e8ff485 RBR |
19 | let mapSize: CGSize |
20 | let lineWidth: CGFloat | |
21 | let evolution: Stage | |
22 | let stages: [CGFloat] | |
77d0155b | 23 | let stageHeight = CGFloat(100.0) |
5e8ff485 RBR |
24 | let padding = CGFloat(5.0) |
25 | ||
5e8ff485 RBR |
26 | var body: some View { |
27 | ZStack(alignment: .topLeading) { | |
28 | ||
29 | // Axis Lines | |
30 | Path { path in | |
31 | path.move(to: CGPoint(x: 0, y: 0)) | |
32 | path.addLine(to: CGPoint(x: 0, y: mapSize.height)) | |
33 | path.addLine(to: CGPoint(x: mapSize.width, y: mapSize.height)) | |
34 | path.move(to: CGPoint(x: mapSize.width, y: mapSize.height)) | |
35 | path.closeSubpath() | |
be897af3 | 36 | }.stroke(Color.Map.axisColor, lineWidth: lineWidth * 2) |
5e8ff485 RBR |
37 | |
38 | // Y Labels | |
be897af3 | 39 | Text("Visible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect( |
e2c37ac1 RBR |
40 | Angle(degrees: -90.0) |
41 | ) | |
42 | .offset(CGSize(width: -35.0, height: 0.0)) | |
be897af3 | 43 | Text("Invisible").font(.Theme.axisLabel).foregroundColor(.Map.labelColor).rotationEffect( |
e2c37ac1 RBR |
44 | Angle(degrees: -90.0) |
45 | ) | |
46 | .offset(CGSize(width: -40.0, height: mapSize.height - 20)) | |
5e8ff485 RBR |
47 | |
48 | // X Labels | |
49 | ||
50 | Text("Uncharted") | |
be897af3 RBR |
51 | .font(.Theme.axisLabel) |
52 | .foregroundColor(.Map.labelColor) | |
77d0155b RBR |
53 | .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading) |
54 | .offset(CGSize(width: 0.0, height: -stageHeight / 4.0)) | |
5e8ff485 | 55 | Text("Industrialised") |
be897af3 RBR |
56 | .font(.Theme.axisLabel) |
57 | .foregroundColor(.Map.labelColor) | |
77d0155b RBR |
58 | .frame(width: mapSize.width / 4, height: stageHeight / 2.0, alignment: .topLeading) |
59 | .offset(CGSize(width: mapSize.width - 100.0, height: -stageHeight / 4.0)) | |
5e8ff485 RBR |
60 | |
61 | Text(evolution.i) | |
be897af3 RBR |
62 | .font(.Theme.axisLabel) |
63 | .foregroundColor(.Map.labelColor) | |
5e8ff485 RBR |
64 | .frame(width: w(stages[0]), height: stageHeight, alignment: .topLeading) |
65 | .offset(CGSize(width: 0.0, height: mapSize.height + padding)) | |
66 | ||
67 | Text(evolution.ii) | |
be897af3 RBR |
68 | .font(.Theme.axisLabel) |
69 | .foregroundColor(.Map.labelColor) | |
5e8ff485 RBR |
70 | .frame(width: w(stages[1]) - w(stages[0]), height: stageHeight, alignment: .topLeading) |
71 | .offset(CGSize(width: w(stages[0]), height: mapSize.height + padding)) | |
72 | ||
73 | Text(evolution.iii) | |
be897af3 RBR |
74 | .font(.Theme.axisLabel) |
75 | .foregroundColor(.Map.labelColor) | |
5e8ff485 RBR |
76 | .frame(width: w(stages[2]) - w(stages[1]), height: stageHeight, alignment: .topLeading) |
77 | .offset(CGSize(width: w(stages[1]), height: mapSize.height + padding)) | |
78 | ||
79 | Text(evolution.iv) | |
be897af3 RBR |
80 | .font(.Theme.axisLabel) |
81 | .foregroundColor(.Map.labelColor) | |
5e8ff485 RBR |
82 | .frame(width: mapSize.width - w(stages[2]), height: stageHeight, alignment: .topLeading) |
83 | .offset(CGSize(width: w(stages[2]), height: mapSize.height + padding)) | |
84 | } | |
85 | } | |
86 | ||
87 | func w(_ dimension: CGFloat) -> CGFloat { | |
88 | max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0)) | |
89 | } | |
90 | } | |
91 | ||
e2c37ac1 RBR |
92 | #Preview { |
93 | MapAxes( | |
94 | mapSize: CGSize(width: 200.0, height: 200.0), lineWidth: CGFloat(1.0), | |
95 | evolution: Stage.stages(.general), stages: [25.0, 50.0, 75.0] | |
96 | ).padding(50.0) | |
5e8ff485 | 97 | } |